<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const users = {
                Alex: {
                    email: 'alex@alex.com',
                    skills: ['HTML', 'CSS', 'JavaScript'],
                    age: 20,
                    isLoggedIn: false,
                    points: 30
                },
                Asab: {
                    email: 'asab@asab.com',
                    skills: ['HTML', 'CSS', 'JavaScript', 'Redux', 'MongoDB', 'Express', 'React', 'Node'],
                    age: 25,
                    isLoggedIn: false,
                    points: 50
                },
                Brook: {
                    email: 'daniel@daniel.com',
                    skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux'],
                    age: 30,
                    isLoggedIn: true,
                    points: 50
                },
                Daniel: {
                    email: 'daniel@alex.com',
                    skills: ['HTML', 'CSS', 'JavaScript', 'Python'],
                    age: 20,
                    isLoggedIn: false,
                    points: 40
                },
                John: {
                    email: 'john@john.com',
                    skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux', 'Node.js'],
                    age: 20,
                    isLoggedIn: true,
                    points: 50
                },
                Thomas: {
                    email: 'thomas@thomas.com',
                    skills: ['HTML', 'CSS', 'JavaScript', 'React'],
                    age: 20,
                    isLoggedIn: false,
                    points: 40
                },
                Paul: {
                    email: 'paul@paul.com',
                    skills: ['HTML', 'CSS', 'JavaScript', 'MongoDB', 'Express', 'React', 'Node'],
                    age: 20,
                    isLoggedIn: false,
                    points: 40
                }
        }
            //1.统计在线人数
            const usersKey = Object.keys(users);
            var logNum = 0;
            usersKey.forEach(usersKey => users[usersKey].isLoggedIn == true ? logNum ++ : logNum);
            console.log('在线人数：'+logNum);

            // const arr = {Alex,Asab,Brook,Daniel,John,Thomas,Paul} = users;
            // const arr2 = [arr.Alex.isLoggedIn,arr.Asab.isLoggedIn,arr.Brook.isLoggedIn,arr.Daniel.isLoggedIn,
            //             arr.John.isLoggedIn,arr.Thomas.isLoggedIn,arr.Paul.isLoggedIn];
            // var logInSum = 0;
            // for(let i = 1;i <= 7;i++){
            //     arr2[i] == true ? logInSum += 1 : logInSum += 0;
            // }
            // console.log(logInSum);
            

            // 2.统计分数大于50的人数
            var pointNum = 0;
            usersKey.forEach(usersKey => users[usersKey].points > 50 ? pointNum ++ : pointNum);
            console.log('分数大于50人数：'+pointNum);

            // const arr3 = [arr.Alex.points,arr.Asab.points,arr.Brook.points,arr.Daniel.points,
            //             arr.John.points,arr.Thomas.points,arr.Paul.points];
            // var pointSum = 0;
            // for(let i = 1;i <= 7;i++){
            //     arr3[i] > 50 ? pointSum += 1 : pointSum += 0;
            // }
            // console.log(pointSum);
            

            //3.查找会MongoDB的人，并打印其名字
            usersKey.forEach(
                usersKey => users[usersKey].skills.includes('MongoDB') ? console.log('会MongoDB的'+usersKey) : null
                );

            // 4.查找同时会：MongoDB， Express，React，和Node 的人，并打印其名字
            usersKey.forEach(
                usersKey => 
                users[usersKey].skills.includes('MongoDB','Express','React','Node') ? console.log('会好多的'+usersKey) : null
                );


        var collection = {
            "1275":{
                "album":"依然范特西",
                "artist":"周杰伦",
                "tracks":[
                    "听妈妈的话",
                    "千里之外"
                ]
                },
            "2468":{
                "album":"西界",
                "artist":"林俊杰",
                "tracks":[
                    "西界",
                    "杀手"
                ]
                },
            "3245":{
                "artist":"许嵩",
                "tracks":[ ]
            },
            "5439":{
                "album":"遇见"
            }
        }

        // 1.定义方法更新记录:
        // 要求：
        // 1).如果传入的value是一个空值，表示将该属性删除
        // 2).传入的prop如果是tracks，则代表添加，其他是修改
        // 3245 tracks '有何不可'
        // 3245 tracks ''   -->删
        // 5439 artist '孙燕姿'
        // 5439 album '逆光'
        var updateRecords = (id,prop,value) => {
                value == "" ? (delete collection[id][prop]) : 
                (prop == "tracks" ? collection[id].tracks.push(value) : collection[id][prop] = value)
        }

        // updateRecords(3245,"tracks","");
        // console.log(collection);
        // updateRecords(3245,"tracks","掀起波澜~");
        // console.log(collection);
        updateRecords(3245,"artist","波澜哥");
        console.log(collection);

    </script>
</body>
</html>